# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=squid
pkgver=6.6
pkgrel=0
_langpack=20230225
pkgdesc="Full-featured Web proxy cache server"
url="http://www.squid-cache.org/"
install="squid.pre-install squid.pre-upgrade"
arch="all"
license="GPL-2.0-or-later"
depends="logrotate"
makedepends="
	heimdal-dev
	libcap-dev
	linux-headers
	openssl-dev>3
	perl-dev
	"
subpackages="$pkgname-openrc $pkgname-doc"
linguas="af ar az bg ca cs da de el es et fa fi fr he hu hy id it ja ka ko lt
	lv ms nl oc pl pt ro ru sk sl spq sr sv th tr uk uz vi zh"
langdir="/usr/share/squid/errors"
source="http://www.squid-cache.org/Versions/v${pkgver%%.*}/squid-$pkgver.tar.xz
	squid-langpack-$_langpack.tar.gz.noauto::http://www.squid-cache.org/Versions/langpack/squid-langpack-$_langpack.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate
	"
pkgusers="squid"
pkggroups="squid"
options="!check"

# secfixes:
#   6.6-r0:
#     - CVE-2023-50269
#   6.5-r0:
#     - CVE-2023-49285
#     - CVE-2023-49286
#   6.4-r0:
#     - CVE-2023-46847
#     - CVE-2023-46846
#     - CVE-2023-46724
#     - CVE-2023-46848
#   6.1-r0:
#     - CVE-2023-49288
#   5.7-r0:
#     - CVE-2022-41317
#   5.2-r0:
#     - CVE-2021-41611
#     - CVE-2021-28116
#   5.0.6-r0:
#     - CVE-2021-28651
#     - CVE-2021-28652
#     - CVE-2021-28662
#     - CVE-2021-31806
#     - CVE-2021-31807
#     - CVE-2021-31808
#     - CVE-2021-33620
#   5.0.5-r0:
#     - CVE-2020-25097
#   4.13.0-r0:
#     - CVE-2020-15810
#     - CVE-2020-15811
#     - CVE-2020-24606
#   4.12.0-r0:
#     - CVE-2020-15049
#   4.10-r0:
#     - CVE-2020-8449
#     - CVE-2020-8450
#     - CVE-2019-12528
#     - CVE-2020-8517
#   4.9-r0:
#     - CVE-2019-18679
#   4.8-r0:
#     - CVE-2019-13345
#   3.5.27-r2:
#     - CVE-2018-1000024
#     - CVE-2018-1000027
#     - CVE-2018-1172

unpack() {
	default_unpack
	mkdir -p "$srcdir"/langpack
	tar -xzf "$srcdir"/squid-langpack-$_langpack.tar.gz.noauto -C "$srcdir"/langpack
}

prepare() {
	default_prepare

	cd "$srcdir"/langpack
	# create symlink names for languages
	./alias-link.sh ln rm . aliases
	# delete non-translation files already installed
	rm -r templates COPYRIGHT TRANSLATORS aliases alias-upgrade alias-link.sh
}

build() {
	CXXFLAGS="$CXXFLAGS -O2 -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--datadir=/usr/share/squid \
		--sysconfdir=/etc/squid \
		--libexecdir=/usr/lib/squid \
		--localstatedir=/var \
		--with-logdir=/var/log/squid \
		--disable-strict-error-checking \
		--disable-arch-native \
		--enable-removal-policies="lru,heap" \
		--enable-auth-digest \
		--enable-auth-basic="getpwnam,NCSA,SMB,SMB_LM,RADIUS" \
		--enable-epoll \
		--enable-external-acl-helpers="file_userip,unix_group,wbinfo_group" \
		--enable-auth-ntlm="fake,SMB_LM" \
		--enable-auth-negotiate="kerberos,wrapper" \
		--disable-mit \
		--enable-heimdal \
		--enable-delay-pools \
		--enable-arp-acl \
		--enable-openssl \
		--enable-ssl-crtd \
		--enable-linux-netfilter \
		--enable-ident-lookups \
		--enable-useragent-log \
		--enable-cache-digests \
		--enable-referer-log \
		--enable-async-io \
		--enable-truncate \
		--enable-arp-acl \
		--enable-htcp \
		--enable-carp \
		--enable-poll \
		--enable-follow-x-forwarded-for \
		--with-large-files \
		--with-default-user=squid \
		--with-openssl

	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.logrotate \
		"$pkgdir"/etc/logrotate.d/squid

	install -d -o squid -g squid \
		"$pkgdir"/var/cache/squid \
		"$pkgdir"/var/log/squid \
		"$pkgdir"/var/run/squid
	chmod +x "$pkgdir"/usr/lib/squid/*

	cp -r "$srcdir"/langpack/* "$pkgdir"/usr/share/squid/errors/
}

squid_kerb_auth() {
	pkgdesc="Squid kerberos authentication helper"

	amove usr/lib/squid/squid_kerb_auth
}

sha512sums="
4ab261ed85ad674288467500aca9d8a48e3918b55f777635c0ba7a2551f248d35536848a5fbf2c946490a818004727f2aed33144f0a3ebab0be36cc4cffb020c  squid-6.6.tar.xz
0ae20713b545b8542fcd4e8dcfca660bb6648c0209ed87db50727efa2cb39d17c9890456a165766c5ce436bd4e01e03f0a2ccfe1029d50c22a942f91c8424808  squid-langpack-20230225.tar.gz.noauto
e3968a6b97baebfe18e1e978c76f6ef7a8a60cfb96dfc2d5199e91a84a065fe964aed6531aa04fe3824c5fd0644adec28ff81ff2f4fed424a29e636829b118d8  squid.initd
7292661de344e8a87d855c83afce49511685d2680effab3afab110e45144c0117935f3bf73ab893c9e6d43f7fb5ba013635e24f6da6daf0eeb895ef2e9b5baa9  squid.confd
89a703fa4f21b6c7c26e64a46fd52407e20f00c34146ade0bea0c4b63d050117c0f8e218f2256a1fbf6abb84f4ec9b0472c9a4092ff6e78f07c4f5a25d0892a5  squid.logrotate
"
